package cn.rdq.iknessplatform.listener;

import cn.rdq.common.constant.RedisConst;
import cn.rdq.common.constant.SysCurrentInfo;
import cn.rdq.common.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
public class OnlineSessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        if (session.isNew()) {
            //在线人数增加
            SysCurrentInfo.incrOnline();
            SysCurrentInfo.incrViewsToday();
        }
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        //在线人数减少
        SysCurrentInfo.descOnline();
    }
}
